@charset "utf-8";

// 定义switch的基础构造
@mixin _switch {
    display: inline-block;
    margin: -.05rem 0;
    > input {
        display: none;
    }
    > .track {
        display: inline-block;
        position: relative;
        width: .50rem;
        height: .3rem;
        padding: .01rem;
        border-radius: .16rem;
        background-color: map-get($switch, bgcolor);
        vertical-align: middle;
        > .handle {
            position: absolute;
            z-index: 1000;
            top: 1px;
            left: 1px;
            @include square(.28rem);
            border-radius: 50%;
            background-color: map-get($switch, ball-color);
            box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
            @include transition(transform .1s ease-out);
        }
        &::after {
            position: absolute;
            left: .15rem;
            content: "\0020";
            width: .34rem;
            height: .28rem;
            background-color: map-get($switch, follow-bgcolor);
            border-radius: 0 .15rem .15rem 0;
            @include transition(transform .13s ease-out);
        }
    }
    > input:checked + .track {
        background-color: map-get($switch, checked-bgcolor);
        > .handle {
            @include transform(translate3d(.2rem, 0, 0));
        }
        &::after {
            @include transform(scale3d(0, 0, 0));
        }
    }
    > input:disabled + .track {
        opacity: .4;
    }
}

/**
 * @module widget
 * @method yo-switch
 * @version 1.0.0
 * @description 构造yo-switch的自定义使用方法
 * @demo http://doyoe.github.io/Yo/demo/widget/yo-switch.html
 * @param {String} $name 定义扩展名称 <1.0.0>
 * @param {Color} $checked-bordercolor 定义switch激活边框色 <1.0.0, 2.0.0>
 * @param {Color} $checked-border-color 定义switch激活边框色 <2.0.0, 2.1.2>
 * @param {Color} $checked-bgcolor 定义switch激活背景色 <1.0.0>
 * @param {Color} $bordercolor 定义switch边框色 <1.0.0, 2.0.0>
 * @param {Color} $border-color 定义switch边框色 <2.0.0, 2.1.2>
 * @param {Color} $bgcolor 定义switch背景色 <1.0.0>
 * @param {Color} $follow-bgcolor 定义switch跟随背景色 <2.1.2>
 * @param {Color} $ball-color 定义switch滑块色 <1.0.0>
 */

@mixin yo-switch(
    $name: default,
    $checked-bgcolor: default,
    $bgcolor: default,
    $follow-bgcolor: default,
    $ball-color: default) {
    // 区别是否新增实例还是修改本身
    $name: if($name == default, "", "-#{$name}");
    // 如果值为default，则取config的定义
    @if $bgcolor == default {
        $bgcolor: map-get($switch, bgcolor);
    }
    @if $checked-bgcolor == default {
        $checked-bgcolor: map-get($switch, checked-bgcolor);
    }
    @if $follow-bgcolor == default {
        $follow-bgcolor: map-get($switch, follow-bgcolor);
    }
    @if $ball-color == default {
        $ball-color: map-get($switch, ball-color);
    }
    .yo-switch#{$name} {
        > .track {
            @if $bgcolor != map-get($switch, bgcolor) {
                background-color: $bgcolor;
            }
            > .handle {
                @if $ball-color != map-get($switch, ball-color) {
                    background-color: $ball-color;
                }
            }
            &::after {
                @if $follow-bgcolor != map-get($switch, follow-bgcolor) {
                    background-color: $follow-bgcolor;
                }
            }
        }
        > input:checked + .track {
            @if $checked-bgcolor != map-get($switch, checked-bgcolor) {
                background-color: $checked-bgcolor;
            }
        }
        // 增量扩展
        @content;
    }
}

// 调用本文件时载入switch基础构造
.yo-switch {
    @include _switch;
}